package gslog

import "strings"

type logLevel int

const (
	LOG_DRIVER_ZAP             = "Zap"
	LOG_DRIVER_SIMPLE          = "Simple"
	LEVEL_TRACE       logLevel = iota
	LEVEL_DEBUG
	LEVEL_INFO
	LEVEL_WARN
	LEVEL_ERROR
	LEVEL_TRACE_TAG = "trace"
	LEVEL_DEBUG_TAG = "debug"
	LEVEL_INFO_TAG  = "info"
	LEVEL_WARN_TAG  = "warn"
	LEVEL_ERROR_TAG = "error"
)

var tagMapLevel = map[string]logLevel{
	LEVEL_DEBUG_TAG: LEVEL_DEBUG,
	LEVEL_INFO_TAG:  LEVEL_INFO,
	LEVEL_WARN_TAG:  LEVEL_WARN,
	LEVEL_ERROR_TAG: LEVEL_ERROR,
	LEVEL_TRACE_TAG: LEVEL_TRACE,
}

var levelMapTag = map[logLevel]string{
	LEVEL_DEBUG: LEVEL_DEBUG_TAG,
	LEVEL_INFO:  LEVEL_INFO_TAG,
	LEVEL_WARN:  LEVEL_WARN_TAG,
	LEVEL_ERROR: LEVEL_ERROR_TAG,
	LEVEL_TRACE: LEVEL_TRACE_TAG,
}

func getLogLevel(level string) logLevel {
	if v, ok := tagMapLevel[level]; ok {
		return v
	}
	return LEVEL_INFO
}

func (l logLevel) String() string {
	if v, ok := levelMapTag[l]; ok {
		return strings.ToUpper(v)
	}
	return "UNKNOWN"
}
